package com.wcgksoft.controller.upload;

import com.wcgksoft.entity.system.SysUser;
import com.wcgksoft.common.util.FileUpload;
import com.wcgksoft.common.util.Layui;
import net.sf.ezmorph.object.DateMorpher;
import net.sf.json.util.JSONUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "upload")
public class Upload {
    @ResponseBody
    @RequestMapping(value = "upload")
    public Layui upload1( HttpServletRequest request, HttpServletResponse response,
                         @RequestParam(value = "file",required = false) CommonsMultipartFile file){
        System.out.println("aaaaaaaaaaaaaaaaaaaaaa");
        System.out.println(file);
        String[] dateFormats = new String[]{"MM-dd","yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss"};
        JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(dateFormats));
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getSession().getAttribute("om_user");
        if (null != file) {
            String image = FileUpload.picvideoupload("upload/picture", "file", request);
        }
        System.out.println("上传成功");
        return Layui.data(0, "个人信息保存成功", 1,null);
    }
}
